<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <!DOCTYPE html>
<html>

<head>
	<base href="/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>回收站</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="static/templet/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/templet/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="static/templet/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="static/templet/css/animate.min.css" rel="stylesheet">
    <link href="static/templet/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<style>
.clearfix:after{
	content:'';
	display:block;
	clear:both;
}
.goBack{
	float:left;
	width:50px;
	margin-top:20px;
}
.pag{
width:90%;
	float:right;
}
</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    <form action="newStation/recycleBin" method="post" id="billForm">
        <div class="row">  
        
        <div class="col-sm-12">
        		<table class="table table-hover">
        			<tr>
        				<td>
							 <input type="text"  value="${param.userName}" name="userName" class="form-control" placeholder="请输入用户名">
        				</td>
        				<td>
							 <input type="text"  value="${param.keyWord}" name="keyWord" class="form-control" placeholder="请输入关键词">
        				</td>
        				<td >
        					<button type="button" class="btn btn-primary" onclick="searchs();">检索</button>&nbsp;&nbsp;&nbsp;
        					<button type="button" class="btn btn-primary" onclick="exportKeyword();">导出</button>
        				</td>
        			</tr>
        		</table>
			</div>      
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th class="text-center"><input type="checkbox" id="checked_all" onclick="checkOrCancelAll();"/>&nbsp;&nbsp;&nbsp;&nbsp;<span id="choose">全选</span></th>
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>关键词</th>
                                    <th>域名</th>
                                    <th>引擎</th>
                                    <th>指数</th>
                                    <th>单价 (元)</th>
                                    <th>修改时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
							<c:forEach items="${page.list}" var="ba" varStatus="vs">
                            	<tr>
                            		<td><input type="checkbox" class="checked_pro" name="checkbox"  value="${ba.id }"/></td>
                                    <td>${ba.id}</td>
									<td>${ba.userName }</td>
									<td>${ba.name }</td>
									<td>${ba.domain }</td>
									<td>
										<c:if test="${ba.engine_code == '01'}">
											百度PC
										</c:if>
										<c:if test="${ba.engine_code == '02'}">
											百度移动
										</c:if>
										<c:if test="${ba.engine_code == '03'}">
											360PC
										</c:if>
										<c:if test="${ba.engine_code == '04'}">
											360移动
										</c:if>
										<c:if test="${ba.engine_code == '05'}">
											神马
										</c:if>
										<c:if test="${ba.engine_code == '06'}">
											搜狗pc
										</c:if>
										<c:if test="${ba.engine_code == '07'}">
											搜狗移动
										</c:if>
									</td>
									<td>
									<c:choose>
											<c:when test="${ba.keyword_index == '-1'}">
												0
											</c:when>
											<c:otherwise>
												${ba.keyword_index }
											</c:otherwise>
										</c:choose>
									</td>
									<td>${ba.price }</td>
									<td>${ba.update_time }</td>
									<td>
										<a href="javascript:keyWordUpdate('${ba.id }');" title="恢复">恢复</a>
										<a href="javascript:deleteK('${ba.id }');" title="删除">删除</a>
									</td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        
                        <jsp:include page="/WEB-INF/jsp/page.jsp">
                        	<jsp:param value="billForm" name="form"/>
                        </jsp:include>
                    </div>
                    <div class="col-sm-12">
		        		<table class="table table-hover">
		        			<tr>
		        				<td style="width:1%;">
        							<span style="float:left;"><button type="button" class="btn btn-danger" onclick="deleteList()">批量删除</button>
        											   <button type="button" class="btn btn-danger" onclick="keyWordUpdateList()">批量恢复</button></span>
		        				</td>
		        			</tr>
		        		</table>
				   </div>
                </div>
            </div>
        </div>
        </form>
    </div>
    <script src="static/templet/js/jquery.min.js?v=2.1.4"></script>
    <script src="static/templet/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="static/templet/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="static/templet/js/plugins/layer/layer.min.js"></script>
    <script src="static/templet/js/iframe.min.js"></script>
    <script src="static/templet/js/plugins/layer/laydate/laydate.js"></script>
    <script type="text/javascript">
    function searchs() {
    	$("#billForm").attr("action","newStation/recycleBin")
    	$("#billForm").submit();
    }
    
    //批量恢复
    function keyWordUpdateList() {
	    //获取所有被选中的记录
	    var rows = document.getElementsByName("checkbox");
	    if (rows.length== 0) {
	        alert("请先选择要删除的记录!");
	        return;
	    }
	    var ids = '';
	    for (var i = 0; i < rows.length; i++) {
	    	if(rows[i].checked){
	    		ids += rows[i].value + ",";
	    	}
	    }
	    ids = ids.substring(0, ids.length - 1);
	    keyWordUpdate(ids);
	}
    
    //恢复
	function keyWordUpdate(ids){
		layer.confirm('关键词确认要恢复吗？',function(index){
			$.ajax({
				type: 'post',
				url: 'newStation/keyWordUpdate?ids='+ids,
				success: function(data){
					layer.msg('恢复成功!',{icon: 1,time:2000});
					setTimeout(function(){
						window.location.reload();
					},1000)
				},
				error:function(data) {
					console.log(data.msg);
				},
			});		
		});
	}
	
	
	//批量删除
	function deleteList() {
	    //获取所有被选中的记录
	    var rows = document.getElementsByName("checkbox");
	    if (rows.length== 0) {
	        alert("请先选择要删除的记录!");
	        return;
	    }
	    var ids = '';
	    for (var i = 0; i < rows.length; i++) {
	    	if(rows[i].checked){
	    		ids += rows[i].value + ",";
	    	}
	    }
	    ids = ids.substring(0, ids.length - 1);
	    deleteK(ids);
	}
	//删除
	function deleteK(ids){
		layer.confirm('确认要删除此关键词吗？',function(index){
			$.ajax({
				type: 'post',
				url: 'newStation/deleteK?ids='+ids,
				success: function(data){
					layer.msg('删除成功!',{icon: 1,time:2000});
					setTimeout(function(){
						window.location.reload();
					},1000)
				},
				error:function(data) {
					console.log(data.msg);
				},
			});		
		});
	}
	
	  //导出
    function exportKeyword(){
    	var total = '${page.total}';
    	if(total > 0) {
	    	var load = layer.load(1, {
		        shade: [0.1,'#fff']
		    });
			$("#billForm").attr("action","newStation/exportRecycleBin")
	    	$("#billForm").submit();
			layer.close(load);
    	} else {
    		alert("未找到数据！");
    	}
    }
	
	 //全选 全不选
    //页面加载的时候,所有的复选框都是未选中的状态
	function checkOrCancelAll(){
		//1.获取checkbo的元素对象
		var chElt=document.getElementById("checked_all");
		//2.获取选中状态
		var checkedElt=chElt.checked;
		//3.若checked=true,将所有的复选框选中,checked=false,将所有的复选框取消
		var allCheck=document.getElementsByName("checkbox");
		//4.循环遍历取出每一个复选框中的元素
		var mySpan=document.getElementById("choose");
		if(checkedElt){
			//全选
			for(var i=0;i<allCheck.length;i++){
				//设置复选框的选中状态
				allCheck[i].checked=true;
			}
			mySpan.innerHTML="取消全选";
		}else{
			//取消全选
			for(var i=0;i<allCheck.length;i++){
				allCheck[i].checked=false;
			}
			mySpan.innerHTML="全选";
		}
	}
	
    </script>

</body>

</html>